package com.sctvcloud.renhe.ui.adapter.holder;

import android.content.Context;
import android.os.Handler;
import android.support.v7.widget.AppCompatImageView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

import com.bigkoo.convenientbanner.holder.Holder;
import com.bumptech.glide.load.resource.drawable.GlideDrawable;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.sctvcloud.renhe.R;
import com.sctvcloud.renhe.beans.SplashLocalAd;
import com.sctvcloud.renhe.ui.utils.GlideUtil;

import java.io.File;

/**
 * Created by Ly on 2016/12/1.
 * 启动页广告图片加载
 */
public class AdInfoHolder implements Holder<Object> {

    protected AppCompatImageView imageView;
    protected CustomFontTextView time_cv;
    protected Handler handler = new Handler();
    private SimpleTarget<GlideDrawable> target = new SimpleTarget<GlideDrawable>() {
        @Override
        public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
            imageView.setImageDrawable(resource);
        }
    };

    @Override
    public View createView(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.adinfo_page, null);
        imageView = (AppCompatImageView) view.findViewById(R.id.ad_av);
        time_cv = (CustomFontTextView) view.findViewById(R.id.time_cv);
//        imageView = (AppCompatImageView) LayoutInflater.from(context).inflate(R.layout.adinfo_page, null);
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        return view;
    }

    @Override
    public void UpdateUI(Context context, int position, Object data) {
//        if (TextUtils.isEmpty(data)) {
//        } else {
//            GlideUtil.getGlid(context, data).into(imageView);
//        }
        if (data instanceof Integer) {
            imageView.setImageResource((Integer) data);
        } else if (data instanceof String) {
            GlideUtil.getGlid(context, (String) data).into(imageView);
        } else if (data instanceof SplashLocalAd) {
            File file = new File(((SplashLocalAd) data).getFilepath());
            GlideUtil.getGlid(context, file).into(imageView);
        }

    }


}
